package jumpInstructions;

import java.io.FileNotFoundException;
import java.io.IOException;

import main.MIPSSimulator;


public class Jal extends MIPSJumpInstruction {
	public Jal(String input) throws FileNotFoundException, IOException {
		myName = "jal";
		parseImmediate(input);
		
		if (!MIPSSimulator.myLabelLocations
				.containsKey(myTarget)) {
			myLabelName = "label" + MIPSSimulator.myLabelCounter;
			MIPSSimulator.myLabelLocations.put(myTarget,
					myLabelName);
			MIPSSimulator.myLabelCounter++;
		} else {
			myLabelName = MIPSSimulator.myLabelLocations
					.get(MIPSSimulator.currentInstructionLocation + myTarget);
		}
	}
	public String toString(){
		return myName + " " + myLabelName;
	}
	
	@Override
	public void execute() {
		MIPSSimulator.myRegisters.put("$ra", MIPSSimulator.PC + 1);
		MIPSSimulator.PC = myTarget;
	}
}
